

filenames_reg<-list.files(pattern="Terugroep_actie_[0-9]{1}.*?.RData" )
filedate_reg<-str_match(filenames_reg, "Terugroep_actie_(.*?).RData" )[,2]
filedate_reg<-gsub("[Jj]anuari", "january",filedate_reg )
filedate_reg<-gsub("[Ff]ebruari", "february",filedate_reg )
filedate_reg<-gsub("[Mm]aart", "march",filedate_reg )
filedate_reg<-gsub("[Mm]ei", "may",filedate_reg )
filedate_reg<-gsub("[Jj]uni", "june",filedate_reg )
filedate_reg<-gsub("[Jj]uli", "july",filedate_reg )
filedate_reg<-gsub("[Aa]ugustus", "august",filedate_reg )
filedate_reg<-gsub("[Oo]ktober", "october",filedate_reg )
Files_reg<-cbind.data.frame(filenames_reg,as.Date(dmy(filedate_reg)),stringsAsFactors=FALSE)
colnames(Files_reg)<-c("path", "date")
Files_reg<- Files_reg[order(Files_reg$date),]
Files_reg$order<-order(Files_reg$date)
rm(filedate_reg, filenames_reg)

#Load starting file (last)# 
load(Files_reg$path[nrow(Files_reg)])

#Drop dots from variable names
names(x)<-gsub("\\.", "",names(x))
#All lower case
names(x)<-tolower(names(x))

#Transform factor in character
i <- sapply(x, is.factor)
x[i] <- lapply(x[i], as.character)

x$publicatiedatumrdw<-as.Date(as.character(x$publicatiedatumrdw),origin="1970-01-01", format="%Y%m%d")
x<-subset(x, select=c(referentiecoderdw, publicatiedatumrdw))
Recallsinfo<-x


for(j in 2:(nrow(Files_reg))) {
  #Load starting file (first)# 
  load(Files_reg$path[j])
  
  #Drop dots from variable names
  names(x)<-gsub("\\.", "",names(x))
  #All lower case
  names(x)<-tolower(names(x))
  
  #Transform factor in character
  i <- sapply(x, is.factor)
  x[i] <- lapply(x[i], as.character)
  
  x$publicatiedatumrdw<-as.Date(as.character(x$publicatiedatumrdw),origin="1970-01-01", format="%Y%m%d")
  x<-subset(x, select=c(referentiecoderdw, publicatiedatumrdw))
  
  Recallsinfo<-rbind(Recallsinfo, x)  
  
}

Recallsinfo<-subset(Recallsinfo, is.na(publicatiedatumrdw)==FALSE)

Recallsinfo$dupl<-duplicated(Recallsinfo)
Recallsinfo<-subset(Recallsinfo, dupl==FALSE)
Recallsinfo$dupl<-NULL

load("Recall_week1.RData")
Recallw<-subset(Recallw, select=c(kenteken, referentiecoderdw))
Recalls<-merge(Recallw, Recallsinfo, by="referentiecoderdw", all.x=TRUE, all.y=FALSE)

Recalls_Date<-subset(Recalls, select=c(kenteken, publicatiedatumrdw))
save(Recalls_Date, file="Link_Recalls_Date.RData")